/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package datas;

import beans.Info;
import beans.Patient;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author havn
 */
public class InfoObj {
    private connector con;

    public InfoObj() {
        con = new connector();
    }

    public List select(int patientid) {
        try {
            List v = new ArrayList();
            CallableStatement call = con.getCon().prepareCall("{call search_info(?)}");
            call.setInt(1, patientid);
            ResultSet rs = call.executeQuery();
            while (rs.next()) {
                Info i = new Info();
                i.setId(rs.getInt("id"));
                i.setPatientid(rs.getInt("patientid"));
                i.setHostpital(rs.getString("hospital"));
                i.setSick(rs.getString("sick"));
                i.setTreatment(rs.getString("treatment"));
                v.add(i);
            }
            return v;
        } catch (SQLException ex) {
            Logger.getLogger(StaffObj.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public boolean insert(Info p) {
        try {
            CallableStatement call = con.getCon().prepareCall("{call insert_patient(?,?,?,?)}");
            call.setInt(1, p.getPatientid());
            call.setString(2, p.getSick());
            call.setString(3, p.getHostpital());
            call.setString(4, p.getTreatment());
            //ResultSet rs = call.executeQuery();
            if (call.executeUpdate() > 0) {
                return true;
            }else{
                return false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(PatientObj.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }
}
